<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class xmlSettings{
	
	private $fileName = 'config/config.xml';
	
	public function check_settings (){
		if (file_exists($this->fileName)){
			$xml = simplexml_load_file($this->fileName);
			if (isset($xml->settings->saId)){
				return TRUE;
			}
		}
		// дописать обработчик ошибки
		return FALSE;
	}
	
	public function get_saId(){
		$xml = simplexml_load_file($this->fileName);
		$saId = (string)$xml->settings->saId;
		if (preg_match('/^\w{8}-\w{4}-\w{4}-\w{4}-\w{12}$/ui', $saId)){
			return $saId;
		}
		else{
			return "SHIT";
		}
	}

	public function get_file_name() {
		return $this->fileName;
	}
	
	public function get_subjects(){
		$xml = simplexml_load_file($this->fileName);
		$tmp = $xml->settings->subjects->asXML();
		$xmlIterator = new SimpleXMLIterator($tmp);
    	foreach($xmlIterator as $name => $data) {
    		$arr[] = (string)$data; 
    	}
		return $arr;
	}
	
	public function get_subj_list($subjId) {
		$xml = simplexml_load_file($this->fileName);
		switch ($subjId) {
			case '-1':
				$tmp = $xml->settings->probSubjListDay1->asXML();
				$xmlIterator = new SimpleXMLIterator($tmp);
		    	foreach($xmlIterator as $name => $data) {
		    		$a = explode(';', (string)$data);
    				$arr[$a[1]] = $a[0]; 
    			}
				return $arr;
			break;
			case '-2':
				$tmp = $xml->settings->probSubjListDay2->asXML();
				$xmlIterator = new SimpleXMLIterator($tmp);
		    	foreach($xmlIterator as $name => $data) {
		    		$a = explode(';', (string)$data);
    				$arr[$a[1]] = $a[0]; 
    			}
				return $arr;				
			break;
		}
		
	}
	
}

?>